package com.adl.hotelmanage.servlet;

import java.io.IOException;



import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.adl.hotelmanage.util.DbUtil;
import com.adl.hotelmanage.po.*;

/**
 * Servlet implementation class adminServlet
 */
@WebServlet("/adminServlet")
public class adminServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public adminServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

        try {      
        	Connection conn = DbUtil.getSQLConn();
      	 PreparedStatement ptmt = null;
       String sql= "select *from t_user"; 
   	ptmt = conn.prepareStatement(sql);
         ptmt.executeQuery(sql);
    	 List<adminuser> userlist = new ArrayList<adminuser>(); 
    	ResultSet resultSet = ptmt.executeQuery(sql); 
     	 
	      while (resultSet.next()) { 
	    	  adminuser user = new adminuser(); 
	    	  user.setUserName(resultSet.getString("user_userName"));
	    	  user.setUserPass(resultSet.getString("user_userPass")); 
	    	  user.setTelphone(resultSet.getString("user_telphone")); 
	    	  user.setDepartment(resultSet.getString("user_department"));
	    	  user.setSex(resultSet.getString("user_sex"));
	    
	        userlist.add(user); 
	     
} 
	      
	      request.setAttribute("userlist", userlist);
	     
	      resultSet.close(); 
	     ptmt.close(); 
	      conn.close(); 
	  
	    } catch (Exception e) { 
	      e.printStackTrace(); 
	    } 
	  
	    request.getRequestDispatcher("user.jsp").forward(request, response); 

}	
}
